package org.farm.product.application.controller;

import org.farm.common.response.Result;
import org.farm.product.application.convert.ProductSpuDtoConvert;
import org.farm.product.application.dto.ProductSpuDto;
import org.farm.product.domain.bo.ProductSpuBo;
import org.farm.product.domain.service.ProductDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Frank Zou
 * @version v0.0.1
 * @date 2025/4/22
 * @description
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    private final ProductDomainService productDomainService;

    @Autowired
    public ProductController(ProductDomainService productDomainService) {
        this.productDomainService = productDomainService;
    }

    /**
     * 新增商品
     * @param productSpuDto 商品信息
     * @return 新增结果
     */
    @PostMapping
    public Result<Boolean> newProduct(ProductSpuDto productSpuDto){
        ProductSpuBo productSpuBo =  ProductSpuDtoConvert.INSTANCE.convertDtoToBo(productSpuDto);
        return Result.success(productDomainService.newProduct(productSpuBo));
    }


}
